Skip to content

Emit references instead of definitions for object literal properties #256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from

Conversation

olafurpg
Copy link
Member

@olafurpg olafurpg commented May 1, 2023

Fixes #252.

Previously, scip-typescript emitted definitions for properties of object literal expressions that got inferred to a concrete type. This was problematic since doing "Find references" didn't behave like it does in VS Code, where it shows the object literal property together with the type's member.

For example, consider

interface Config { property: number }
const x: Config = { property: 42 }

After this PR, the property in property: 42 becomes a regular reference to Config.property instead of being its own definition. This means that "Find references" now works like it does in VS Code.

Test plan

See updated snapshots.

@olafurpg olafurpg requested a review from SuperAuguste May 1, 2023 10:17
@olafurpg olafurpg force-pushed the olafurpg/object-literals branch from e0f5f2e to cac25e3 Compare May 1, 2023 11:44
@SuperAuguste
Copy link
Contributor

Resolved everything here; this is some of the hackiest stuff I've put together in a while so heads up - it seems to work though :)

@olafurpg olafurpg force-pushed the olafurpg/object-literals branch 2 times, most recently from 6b66709 to 12c600f Compare July 14, 2023 12:27
@olafurpg
Copy link
Member Author

Finally got a moment to look again into this PR and fixed one big remaining blocker to merge this PR. This PR is big and I want to make the changes low risk to merge as possible. I will need a few more iterations before it's safe to merge but I'm eager to get it through the finish line since it fixes a ton of very common navigation quirks.

@olafurpg olafurpg force-pushed the olafurpg/object-literals branch from a11214c to bf1b590 Compare July 17, 2023 12:18
@olafurpg olafurpg requested a review from valerybugakov July 17, 2023 12:21
@olafurpg
Copy link
Member Author

@valerybugakov @SuperAuguste this PR is ready for review now. I cleaned up the commit history so that you can only review the differences in the indexed output by looking at the diff of the last commit. The logic in updateAssignedTypeMap is tricky to reason about because it's inherently complicated to mirror TypeScript typing rules. I did my best to keep the code clean, and I think the code is much cleaner now compared to how we inferred implementation relationships before this PR.

@rodion-m
Copy link

What prevents us from merging this?

@olafurpg
Copy link
Member Author

@rodion-m main reason this hasn't been merged yet is because I'm personally working on other projects and haven't found the time to do the rebase, find reviewers, cut a release and communicate the changes (along with addressing followup feedback). I think the changes in this PR are a significant improvement to the TypeScript/JavaScript navigation experience. I'd love to see this land eventually but don't have an ETA for it at the moment.

kritzcreek pushed a commit that referenced this pull request Sep 30, 2024
kritzcreek pushed a commit that referenced this pull request Sep 30, 2024
kritzcreek pushed a commit that referenced this pull request Sep 30, 2024
kritzcreek pushed a commit that referenced this pull request Sep 30, 2024
Simpler alternative to #256

This follows the implementation I found in the TypeScript goToDefinition service https://github.com/microsoft/TypeScript/blob/88809467e8761e71483e2f4948ef411d8e447188/src/services/goToDefinition.ts#L307-L316

Leans on the TypeScript compilers getContextualType function to resolve object literals to the interfaces, or type definitions they are being checked against. This means we generate useful references in a lot more places, where we'd generate "dead" definitions before.
Test plan

Ports all tests from #256 and adds some basic new ones. Check the updated snapshot output to gauge the improvement or if there are any regressions.
@kritzcreek
Copy link
Contributor

Superseeded by #373

Thanks a lot for all the great test cases in this PR!

@kritzcreek kritzcreek closed this Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Emit references instead of definitions for properties on object literals that implement an interface
4 participants